#include "schemewindow.h"
#include "centrifier.h"

#include <QIcon>

SchemeWindow::SchemeWindow(IToolBox* toolbox)
{
    init(toolbox);
    createScheme();
}

SchemeWindow::SchemeWindow(IToolBox *toolbox, QString file)
{
    init(toolbox);
    loadFromFile(file);
}

SchemeWindow::~SchemeWindow()
{
    if (scheme != NULL)
        delete scheme;
}

void SchemeWindow::init(IToolBox* toolbox)
{
    isModified = false;
    scheme = NULL;

    //Создаём холст
    canvas = new DrawPanel(this);
    canvas->initToolBox(toolbox);
    canvas->setFixedSize(640,480);

    //Создаём область с полосами прокрутки
    scrollPanel = new QScrollArea(this);

    //Центрирование контейнером
    centrifier = new Centrifier(scrollPanel,canvas,this);
    //Добавляем всё на окно
    this->setWidget(scrollPanel);

    //Добавляем окну возможности
    appendFeatures("Save|SaveAs|Cut|Copy|Paste|Emulate|Generators|Impulses|Watches|ExportImage");
    appendFeatures("SchemeTools");
    appendFeatures("Mouse|SaveDoc|OpenDoc");
    appendFeatures("SWire|SText|SRegion|Analyze");
    //Настраиваем окно
    setWindowTitle(tr("Scheme:"));
    setWindowIcon(QIcon(":/ui/Images/UI/document-window.png"));
    setMinimumSize(300,240);
}

void SchemeWindow::createScheme()
{
    if (scheme != NULL)
        delete scheme;
    scheme = new MicroScheme();
    canvas->setScheme(scheme);
}

void SchemeWindow::loadFromFile(QString file)
{
    if (scheme != NULL)
        delete scheme;
    scheme = new MicroScheme();
    canvas->setScheme(scheme);
}

void SchemeWindow::save()
{

}

void SchemeWindow::saveAs()
{

}
